package com.tcu.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tcu.order.entity.OrderItem;
import com.tcu.order.mapper.OrderItemMapper;
import com.tcu.order.service.IOrderItemService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderItemServiceImpl extends ServiceImpl<OrderItemMapper, OrderItem> implements IOrderItemService {

    @Override
    public List<OrderItem> getAllItemByOid(String orderId) {

        QueryWrapper<OrderItem> wrapper = new QueryWrapper<>();
        wrapper.eq("order_id",orderId);

        List<OrderItem> orderItems = baseMapper.selectList(wrapper);
        return orderItems;
    }

    @Override
    public Integer deleteItemByOid(String orderId) {
        QueryWrapper<OrderItem> wrapper = new QueryWrapper<>();
        wrapper.eq("order_id",orderId);

        int delete = baseMapper.delete(wrapper);

        return delete;
    }

    @Override
    public List<OrderItem> getItemByType(String orderId, String typeId) {
        QueryWrapper<OrderItem> wrapper = new QueryWrapper<>();
        wrapper.eq("order_id",orderId)
                .eq("serve_type_id",typeId);
        List<OrderItem> orderItems = baseMapper.selectList(wrapper);
        return orderItems;
    }
}
